menuList[3].onclick();
console.log("12313212313132");
// 获取数据并渲染
current=1;
pageSize=10;
let result;
let shopInfo = document.getElementById("shopid")
async function fun(flagOptions){
    let checkAll = document.querySelector("#checkAll");
    checkAll.checked = false;
    dels=[];
    result = await getData(current,pageSize);
    console.log(result);
    counts = result.page.pageSizeTotal;
    console.log(counts);
    console.log(current);
    pages = result.page.pageNoTotal;
    pageFun({
        current:current,
        pages:pages,
        counts:counts,
        flagOptions:flagOptions,
        pageSize:pageSize
    })
    
}
fun(0);
function getData(current,pageSize){
    console.warn(shopInfo.value);
    return new Promise((resolve, reject) => {
        axios({
            url:'/admin/store/findAllShopComment',
            method:'GET',
            params:{
                page:current,
                size:pageSize,
                shopId:shopInfo.value
                }
            })
            .then(data => {
                if(data.data.err==0){
                    if(data.data.data.code==20001){
                        explain({
                            code:3,
                            msg:"该店铺暂无评论",
                            time:3000
                        })
                    }else{
                        decorateFun(data.data)
                        resolve(data.data.data);
                    }
                }else{
                    location.href='/admin/error'
                }
             
            })
            .catch(err => {
                console.log(err);
            })
    });
   
}
// 批量删除
function openDeleteStoresCommentFun(){
    console.log(dels);
    if(dels.length==0){
        explain({
            code:3,
            msg:"请选择需要删除的评论",
            time:3000
        })
    }else{
        pointFun({
            code:13,
            msg:"是否确认删除选中的评论"
        })
    }
}
function deleteStoresCommentFun(){
    axios({
        url:'/admin/store/deleteShopComments',
        method:'GET',
        params:{
            ids:dels
        }
    })
    .then(data => {
        console.log(data);
        if(data.data.code==20000){
            closeFunStore();
            fun(0);
            explain({
                code:1,
                msg:"删除成功",
                time:3000
            })
        }
    })
    .catch(err => {
        console.log(err);
    })
}
// 删除单个评论
let shopid;
function openDeleteStoreCommentFun(e){
    e=e || window.event;
    var target=e.target || e.srcElement;
    shopid=target.getAttribute('name');
    pointFun({
        code:12,
        msg:"是否删除该评论"
    })
    console.warn(target.getAttribute('name'));
}
function deleteStoreCommentFun(){
    axios({
        url:'/admin/store/deleteAShopComment',
        method:'DELETE',
        params:{
            gCommentId:shopid,
        }
    })
    .then(data => {
        console.log(data);
        if(data.data.code==20000){
            closeFunStore();
            fun(0);
            explain({
                code:1,
                msg:"删除成功",
                time:3000
            })
        }
    })
    .catch(err => {
        console.log(err);
    })
}

// 渲染页面
function decorateFun(data){
    let tbodyMenu = cl("tbodyMenu");
    let dataNums = cl("dataNums");
    let pageMessage = cl("pageMessage");
    let end;
    console.log(data.data.data);
    if(current==1){
        end=data.data.data.length;
    }else{
        end =parseInt(current-1)*parseInt(data.data.data.size)+parseInt(data.data.data.length);
    }
    console.warn(data.data.data.length);
    dataNums.innerHTML = data.data.data.length;
    pageMessage.innerHTML = `第${(current-1)*data.data.page.pageNo+1}到${end}条记录，共${data.data.page.pageSizeTotal}条`;
    tbodyMenu.innerHTML ="";
    let i=0;
    for(let key of data.data.data){
        console.log(key.path.length);
        if(key.path.length==0){
            tbodyMenu.innerHTML += `
            <tr>
                <td><input type="checkbox" class="checkbox" name="${key.gcommentId}" onclick="checkboxFun()" target="${i}"  ></td>
                <td>${key.nickName}</td>
                <td name="${key.userId}">
                    <img class="headimgSmall" src="${key.img}" style="max-width:100px;" alt="">
                </td>
                <td style="max-width:100px" >
                     <a href="/admin/goods/goodsDetail?goodsId=${key.goodsId}">${key.goodsName}</a>
                </td>
                <td  name="${key.userId}">
                    <img src="${key.cover}" style="max-width:100px;margin-top:10px" alt="">
                 </td>
                <td style="max-width:200px;">${key.gcomment}</td>
                <td>
                    该用户未发表图片
                </td>
                <td>${key.time== null?'无':key.time}</td>
                <td>
                    <button class="btn delBtn"><i name="${key.gcommentId}" onclick="openDeleteStoreCommentFun()" class="iconfont shanchu"></i></button>
                </td>
            </tr>
                `
        }else if(key.path.length==1){
                tbodyMenu.innerHTML += `
                <tr>
                    <td><input type="checkbox" class="checkbox" name="${key.gcommentId}" onclick="checkboxFun()" target="${i}"  ></td>
                    <td>${key.nickName}</td>
                    <td  name="${key.userId}">
                        <img class="headimgSmall" src="${key.img}" style="max-width:100px;" alt="图片加载失败">
                    </td>
                    <td style="max-width:100px">
                         <a href="/admin/goods/goodsDetail?goodsId=${key.goodsId}">${key.goodsName}</a>
                    </td>
                    <td  name="${key.userId}">
                        <img src="${key.cover}" style="max-width:100px;" alt="图片加载失败">
                     </td>
                    <td style="max-width:200px;">${key.gcomment}</td>
                    <td>
                    <img src="${key.path[0]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    </td>
                    <td>${key.time== null?'无':key.time}</td>
                    <td>
                        <button class="btn delBtn"><i name="${key.gcommentId}" onclick="openDeleteStoreCommentFun()" class="iconfont shanchu"></i></button>
                    </td>
                </tr>
                    `
        }else if(key.path.length==2){
            tbodyMenu.innerHTML += `
            <tr>
                <td><input type="checkbox" class="checkbox" name="${key.gcommentId}" onclick="checkboxFun()" target="${i}"  ></td>
                <td>${key.nickName}</td>
                <td  name="${key.userId}">
                    <img class="headimgSmall" src="${key.img}" style="max-width:100px;" alt="图片加载失败">
                </td>
                <td style="max-width:100px">
                     <a href="/admin/goods/goodsDetail?goodsId=${key.goodsId}">${key.goodsName}</a>
                </td>
                <td  name="${key.userId}">
                    <img src="${key.cover}" style="max-width:100px;" alt="图片加载失败">
                 </td>
                <td style="max-width:200px;">${key.gcomment}</td>
                <td>
                <img src="${key.path[0]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                <img src="${key.path[1]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                </td>
                <td>${key.time== null?'无':key.time}</td>
                <td>
                    <button class="btn delBtn"><i name="${key.gcommentId}" onclick="openDeleteStoreCommentFun()" class="iconfont shanchu"></i></button>
                </td>
            </tr>
                `
        }else if(key.path.length==3){
            tbodyMenu.innerHTML += `
            <tr>
                <td><input type="checkbox" class="checkbox" name="${key.gcommentId}" onclick="checkboxFun()" target="${i}"  ></td>
                <td>${key.nickName}</td>
                <td  name="${key.userId}">
                    <img class="headimgSmall" src="${key.img}" style="max-width:100px;" alt="图片加载失败">
                </td>
                <td style="max-width:100px">
                     <a href="/admin/goods/goodsDetail?goodsId=${key.goodsId}">${key.goodsName}</a>
                </td>
                <td  name="${key.userId}">
                    <img src="${key.cover}" style="max-width:100px;" alt="图片加载失败">
                 </td>
                <td style="max-width:200px;">${key.gcomment}</td>
                <td>
                <img src="${key.path[0]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                <img src="${key.path[1]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                <img src="${key.path[2]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                </td>
                <td>${key.time== null?'无':key.time}</td>
                <td>
                    <button class="btn delBtn"><i name="${key.gcommentId}" onclick="openDeleteStoreCommentFun()" class="iconfont shanchu"></i></button>
                </td>
            </tr>
                `
    }else if(key.path.length==4){
                tbodyMenu.innerHTML += `
                <tr>
                    <td><input type="checkbox" class="checkbox" name="${key.gcommentId}" onclick="checkboxFun()" target="${i}"  ></td>
                    <td>${key.nickName}</td>
                    <td  name="${key.userId}">
                        <img class="headimgSmall" src="${key.img}" style="max-width:100px;" alt="图片加载失败">
                    </td>
                    <td style="max-width:100px">
                         <a href="/admin/goods/goodsDetail?goodsId=${key.goodsId}">${key.goodsName}</a>
                    </td>
                    <td  name="${key.userId}">
                        <img src="${key.cover}" style="max-width:100px;" alt="图片加载失败">
                     </td>
                    <td style="max-width:200px;">${key.gcomment}</td>
                    <td>
                    <img src="${key.path[0]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    <img src="${key.path[1]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    <img src="${key.path[2]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    <img src="${key.path[3]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    </td>
                    <td>${key.time== null?'无':key.time}</td>
                    <td>
                        <button class="btn delBtn"><i name="${key.gcommentId}" onclick="openDeleteStoreCommentFun()" class="iconfont shanchu"></i></button>
                    </td>
                </tr>
                    `
            }else if(key.path.length==5){
                tbodyMenu.innerHTML += `
                <tr>
                    <td><input type="checkbox" class="checkbox" name="${key.gcommentId}" onclick="checkboxFun()" target="${i}"  ></td>
                    <td>${key.nickName}</td>
                    <td  name="${key.userId}">
                        <img class="headimgSmall" src="${key.img}" style="max-width:100px;" alt="图片加载失败">
                    </td>
                    <td style="max-width:100px">
                         <a href="/admin/goods/goodsDetail?goodsId=${key.goodsId}">${key.goodsName}</a>
                    </td>
                    <td  name="${key.userId}">
                        <img src="${key.cover}" style="max-width:100px;" alt="图片加载失败">
                     </td>
                    <td style="max-width:200px;">${key.gcomment}</td>
                    <td>
                    <img src="${key.path[0]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    <img src="${key.path[1]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    <img src="${key.path[2]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    <img src="${key.path[3]}" style="max-width:100px;margin-top:10px" alt="图片加载失败">
                    </td>
                    <td>${key.time== null?'无':key.time}</td>
                    <td>
                        <button class="btn delBtn"><i name="${key.gcommentId}" onclick="openDeleteStoreCommentFun()" class="iconfont shanchu"></i></button>
                    </td>
                </tr>
                    `
            }
        i++
    }
}
// 输入框回车事件
function inputEnterFun(){
    console.log("a");
    if(event.keyCode == 13){
        searchByStorename()
    }
}

// 页面刷新
function reloadFun(){
    location.reload();
}

// 选择每页展示数量
function chooseSizeFun(){
    let selectNums = document.getElementById("selectNums");
    console.log(selectNums.children[1]);
    console.warn(selectNums.value);
    current = 1;
    pageSize =selectNums.value;
    fun(1);
    for(let i=0;i<selectNums.children.length;i++) {
        if(selectNums.children.length[i]==selectNums.value){
            selectNums.children.length[i].select="select";
        }
    }
}
// 关闭函数
function closeFunStore(){
    alertWindow = document.getElementsByClassName("alertWindow")[0];
    let covers = document.getElementsByClassName("covers")[0];
    covers.style.display = "none";
    alertWindow.style.display = "none";
}
// 点击返回上一页
function returnFun(){
    window.history.back();  
}